
$(function () {
    // 滚动广告
    $(window).resize(function () {
        var width = $(window).width();
        $('div[name=touchslider-item] a').css('width', width);
        $('#touchslider-viewport').css('height', 300 * (width / 640) - 10);
    }).resize();
    $("#touchslider").touchSlider({ mouseTouch: true, autoplay: true });

    // Soo快报
    var _notice_count = $('#noticelist li').length;
    var _count_i = 0;
    var isdesc = false, isfirst = true;
    function notice() {
        if (_notice_count == 1) { return; }

        // 第一次滚动
        if (isfirst) { _count_i++; isfirst = false; }
        $('#noticelist').animate({ 'margin-top': '-' + (2 * _count_i) + 'rem' }, 500);

        if (_count_i == (_notice_count - 1)) {
            isdesc = true;
        } else if (_count_i == 0) { isdesc = false; }

        if (isdesc) { _count_i--; } else { _count_i++; }
    }
    var notice = setInterval(notice, 3000);

    // 懒加载
    $('img.lazy').lazyload({
        placeholder: "../../images/grey.gif",
        event: "scroll",
        threshold: 100,
        failure_limit: 10
    });

    // 懒加载
    $('img.lazy').lazyload({
        placeholder: "../../images/grey.gif",
        event: "scroll",
        threshold: 100,
        skip_invisible: true,
        failure_limit: 10
    });

    // 置顶 
    var _gotop = $('#gotop');
    function run_loading() {
        var height = $(window).height();
        var top = $(window).scrollTop();
        if (top > height / 2) {
            _gotop.show();
        } else {
            _gotop.hide();
        };
    };
    $(window).scroll(run_loading);


    // 星商店

    var mksxdp = $(window).width() * 0.39;
    var addheight = 15;
    $("#wrapper").css("height", (mksxdp + addheight) + "px"); // 计算wrapper高度
    $("#scroller").css("width", $(".mksxdp").length * ($(window).width() * 0.5) + "px");
    $("#fillmksisdiv").css("height", (mksxdp + addheight) + "px");    // 填充div的高度
    $(".mksxdp").css("width", $(window).width() * 0.48 + "px");

    var myScroll;
    function loaded() {
        myScroll = new IScroll('#wrapper', { eventPassthrough: true, scrollX: true, scrollY: false, preventDefault: false, scrollbars: 'custom' });
        myScroll.on('scrollEnd', function () {
            $("img.lazy").lazyload({
                placeholder: "../../images/grey.gif",
                threshold: 100,
                failure_limit: 10,
                container: $("#wrapper")
            });
        })
    }
    loaded();

})
